////////////////////////////////////////////////////////////////////////////////
//
//  FLYING KIWI BV
//  Copyright 2010 Flying Kiwi BV
//  All Rights Reserved.
//
//  NOTICE: Flying Kiwi permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
package plantool.modules.menu.display {
	//--------------------------------------------------------------------------
	//  Imports
	//--------------------------------------------------------------------------
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormatAlign;
	
	import kiwi.components.ComponentSkin;
	import kiwi.components.skins.IButtonSkin;
	
	import plantool.helpers.TextFieldHelper;
	
	//--------------------------------------------------------------------------
	//  [Metadata (Events, Style, Effects etc)]
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//  Class declaration
	//--------------------------------------------------------------------------
	public class MenuItemButtonSkin extends ComponentSkin implements IButtonSkin {
		//--------------------------------------------------------------------------
		//Class constants
		//--------------------------------------------------------------------------
		private const STATE_NORMAL:uint		= 0;
		private const STATE_OVER:uint		= 1;
		
		//--------------------------------------------------------------------------
		//Class variables
		//--------------------------------------------------------------------------
		private var _state:Number			= 0;
		private var _width:Number			= 150;
		private var _height:Number			= 22;
		private var _tf:TextField			= null;
		
		//--------------------------------------------------------------------------
		//Class properties
		//--------------------------------------------------------------------------
		override public function set text(value:String):void { _tf.text = value; }
		override public function get text():String { return _tf.text; }
		public override function get height():Number { return _height; }
		public override function set height(value:Number):void { _height = value; }
		public override function get width():Number { return _width; }
		public override function set width(value:Number):void { _height = value; }
		
		//--------------------------------------------------------------------------
		//Constructor and Destructor
		//--------------------------------------------------------------------------
		public function MenuItemButtonSkin() {
			//create textfield
			_tf	= TextFieldHelper.createInfoTf(TextFieldAutoSize.NONE, TextFormatAlign.CENTER, false, false, 0);
			addChild(_tf);
		}
		
		public override function dispose():void {
		}
		
		//--------------------------------------------------------------------------
		//Class methods
		//--------------------------------------------------------------------------
		public function mouseHandler(event:MouseEvent):void {
			switch (event.type) {
				case MouseEvent.MOUSE_OVER:
					_state = STATE_OVER;
					invalidate();
					break;
				case MouseEvent.MOUSE_OUT:
					_state = STATE_NORMAL;
					invalidate();
					break;
			}
		}
		
		protected override function update():void {
			//set tf size
			_tf.width	= width;
			_tf.y		= (height - _tf.height) / 2;
			
			//draw background
			graphics.clear();
			switch (_state) {
				case STATE_NORMAL:
					_tf.textColor = 0;
					
					graphics.beginFill(0xCCCCCC, 0.25);
					graphics.drawRect(0, 0, width, height);
					graphics.endFill();
					break;
				case STATE_OVER:
					_tf.textColor = 0xFF6600;
					
					graphics.beginFill(0, 0.25);
					graphics.drawRect(0, 0, width, height);
					graphics.endFill();
					break;
			}
		}
	}
}